/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recursion;

/**
 *
 * @author parallels
 */
public class Fibonacci {
    
    public static int calc (int n) {
        
        if ((n == 0) || (n == 1))
            return n;
        
        int fnM2 = 0;
        int fnM1 = 1;
        int fib = 0;
        
        for (int i=2; i <= n; ++i) {
            fib = fnM1 + fnM2;
            fnM2 = fnM1;
            fnM1 = fib;
        }
        return fib;
        
    }
    
    public static int recursiveCalc (int n) {
        // or con tecla altGR + 1 
        
        if ((n == 0) || (n == 1)) {
            return n;
        } else {
            return recursiveCalc(n - 1) + recursiveCalc(n - 2);
        }
        
    }
    
}
